<template>
  <div class="patient-info" v-if="true">
    <div class="patient-info-inside">
      <div class="header">
        <div class="left item">
          <img
              alt="左侧"
              src="@/components/assets/images/design/1-12.webp"
          />
        </div>
        <div class="middle item">个人信息</div>
        <div class="right item">
          <img
              alt="右侧"
              src="@/components/assets/images/design/1-12.webp"
          />
        </div>
      </div>
      <el-row class="patient-info-area">
        <el-col :span="24" class="first">
          <div class="sign">姓名</div>
          <div class="content">{{patientInfo?.result?.name}}</div>
        </el-col>
        <el-col :span="24">
          <div class="sign">性别</div>
          <div class="content">{{patientInfo?.result?.sex}}</div>
        </el-col>
        <el-col :span="24">
          <div class="sign">出生日期</div>
          <div class="content">{{patientInfo?.result?.birthday}}</div>
        </el-col>
        <el-col :span="24" v-if="!FromFileApply">
          <div class="sign">联系电话</div>
          <div class="content">{{patientInfo?.result?.phone}}</div>
        </el-col>
        <el-col :span="24">
          <div class="sign">身份证号</div>
          <div class="content">{{patientInfo?.result?.idNo}}</div>
        </el-col>
        <el-col :span="24" class="last">
          <div class="item left" @click="handleEdit" v-if="!FromFileApply">
            修改电话
          </div>
          <div class="item right" @click="handleSure">确定</div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PatientInfo',

  componentName: "PatientInfo",

  components: {},

  props: {
    isUseReq: {
      type: Boolean,
      default: true,
    },
    FromFileApply: {
      type: Boolean,
      default: false,
    }
  },

  data() {
    return {}
  },

  computed: {
    // 患者信息
    patientInfo() {
      if(!this.isUseReq){
        let cardTypeInfo = this.$store.getters["DRCbiz/getCardTypeInfo"]
        return this.parseUserMsg(cardTypeInfo.cardInfo)
      }else{
        return this.$store.getters['DRCbiz/getPatientInfo']
      }
    }
  },

  mounted() {
  },

  methods: {
    /**
     * @name 解析身份
     */
    parseUserMsg(data) {
      const obj = JSON.parse(data);
      const idNum = obj.IDNum;
      let birthday = "";
      if (idNum && idNum.length === 18) {
        // 提取出生年月日（格式：YYYY-MM-DD）
        const year = idNum.substring(6, 10);
        const month = idNum.substring(10, 12);
        const day = idNum.substring(12, 14);
        birthday = `${year}-${month}-${day}`;
      }
      const name = obj.Name;
      const gender = obj.Gender; // 如果Gender为空，可以根据身份证号判断性别
      let genderInfo = gender;
      if (!gender && idNum && idNum.length === 18) {
        // 身份证第17位为奇数表示男，偶数表示女
        const genderCode = parseInt(idNum.charAt(16), 10);
        genderInfo = genderCode % 2 === 1 ? "男" : "女";
      }
      return {
        result: {
            name,
            sex: genderInfo,
            birthday,
            idNo: idNum
        }
      }
    },

    // 点击患者确定
    handleSure() {
      console.log('点击患者确定');
      this.$emit('handlePatientInfoSure')
    },

    // 修改患者手机号
    handleEdit(){
      console.log('修改患者手机号')
    },
  },
}

</script>

<style scoped lang="scss">
@import "./assets/style";
</style>